package com.shunda.ysdgj.manager.controller.system;

import com.shunda.ysdgj.manager.service.system.SysUserService;
import com.shunda.ysdgj.model.dto.base.IdsDto;
import com.shunda.ysdgj.model.dto.system.SysUserFindDto;
import com.shunda.ysdgj.model.entity.system.SysUser;
import com.shunda.ysdgj.model.vo.ResultVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "系统管理员接口")
@RestController
@RequestMapping("/api/v1/admin/system/user")
@RequiredArgsConstructor
public class SysUserController {

    private final SysUserService sysUserService;

    @Operation(summary = "分页获取系统管理员列表")
    @PostMapping("list")
    public ResultVo list(@RequestBody SysUserFindDto sysUserFindDto) {
        return ResultVo.success(sysUserService.findByPage(sysUserFindDto));
    }

    @Operation(summary = "添加系统管理员")
    @PostMapping("add")
    public ResultVo add(@RequestBody SysUser sysUser) {
        if (!sysUserService.add(sysUser)) {
            return ResultVo.fail();
        }
        return ResultVo.success();
    }

    @Operation(summary = "修改系统管理员")
    @PostMapping("modify")
    public ResultVo modify(@RequestBody SysUser sysUser) {
        if (!sysUserService.modify(sysUser)) {
            return ResultVo.fail();
        }
        return ResultVo.success();
    }

    @Operation(summary = "删除系统管理员")
    @PostMapping("delete")
    public ResultVo delete(@RequestBody IdsDto idsDto) {
        if (!sysUserService.deleteByIds(idsDto)) {
            return ResultVo.fail();
        }
        return ResultVo.success();
    }

}
